//author:kakake
var Model = /** @class */ (function () {
    function Model() {
    }
    return Model;
}());

//author:kakake
var Common = /** @class */ (function () {
    function Common() {
    }
    return Common;
}());

//author:kakake
var tsgbdataDao = /** @class */ (function () {
    function tsgbdataDao() {
        this.dbConn = TSLobsterAPI.Program.GetDbConn();
    }
    return tsgbdataDao;
}());

//author:kakake
var tsgbdataService = /** @class */ (function () {
    function tsgbdataService() {
    }
    return tsgbdataService;
}());

//author:kakake
var tsgbdataController = /** @class */ (function () {
    function tsgbdataController() {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn()
        };
    }
    //获取数据分类
    tsgbdataController.prototype.gettree = function () {
        var strsql = "SELECT id,nodeName,parentId FROM treeview";
        var list = TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql);
        var _root = TSLobsterAPI.Utils.findlist(list, 'id', 0)[0]; //根节点
        TSLobsterAPI.Utils.TrackLog("gettree", _root);
        var tree = [];
        var lv = 1;
        var node = {};
        node["id"] = _root['id'];
        node["name"] = _root['nodeName'];
        node["title"] = _root['nodeName'];
        node["parentid"] = _root['parentId'];
        node["spread"] = true;
        node["href"] = "";
        node["selected"] = false;
        node["disabled"] = false;
        node["level"] = 1;
        node["children"] = this.bulidtree(list, _root['id'], lv + 1);
        tree.push(node);
        return tree;
    };
    tsgbdataController.prototype.bulidtree = function (list, pid, lv) {
        var _this = this;
        var _childlist = TSLobsterAPI.Utils.findlist(list, 'parentId', pid);
        var treelist = [];
        _childlist.forEach(function (i) {
            var node = {};
            node["id"] = i['id'];
            node["name"] = i['nodeName'];
            node["title"] = i['nodeName'];
            node["parentid"] = i['parentId'];
            node["spread"] = true;
            node["href"] = "";
            node["selected"] = false;
            node["disabled"] = false;
            node["level"] = lv;
            node["children"] = _this.bulidtree(list, i['id'], lv + 1);
            treelist.push(node);
        });
        return treelist;
    };
    //获取元数据
    tsgbdataController.prototype.getmetadata = function () {
        var cid = TSLobsterAPI.Program.RequestQuery("cid", "");
        var pid = TSLobsterAPI.Program.RequestQuery("pid", "");
        var lv = TSLobsterAPI.Program.RequestQuery("lv", "");
        var onlyValue = TSLobsterAPI.Program.RequestQuery("onlyValue", "");
        var keywords = TSLobsterAPI.Program.RequestQuery("param", "");
        var pageInfo = {
            key: "数据元标识符",
            page: TSLobsterAPI.Program.RequestQuery('page', 0),
            perPage: TSLobsterAPI.Program.RequestQuery('limit', 10),
            totalRecord: 0,
            totalPage: 0
        };
        var strsql = "";
        if ((parseInt(lv) == 2 && cid == "*1") || (parseInt(lv) == 3 && pid == "*1")) {
            strsql = "SELECT 内部标识符, 数据集编码, a.数据元标识符, a.数据元名称, 定义, 类型, 格式, 数据元允许值, b.值域编码                         FROM 城乡居民健康档案基本数据集WS365 a                         LEFT JOIN 城乡居民健康档案基本数据集值域目录WS365 b ON a.数据元标识符 = b.数据元标识符";
        }
        else if ((parseInt(lv) == 2 && cid == "*2") || (parseInt(lv) == 3 && pid == "*2")) {
            strsql = "SELECT 内部标识符, 数据集编码, a.数据元标识符, a.数据元名称, 定义, 类型, 格式, 数据元允许值, b.值域编码                         FROM dbo.电子病历数据集WS445 a                         LEFT JOIN dbo.电子病历数据集值域目录WS445 b ON a.数据元标识符 = b.数据元标识符";
        }
        else if ((parseInt(lv) == 2 && cid == "*3") || (parseInt(lv) == 3 && pid == "*3")) {
            strsql = "SELECT 内部标识符, 数据集编号 AS 数据集编码, a.数据元标识符, a.数据元名称, 定义, 类型, 格式, 数据元允许值, b.值域编码                         FROM dbo.[公共卫生数据集WS371-377] a                         LEFT JOIN dbo.[公共卫生数据集值域目录WS371-377] b ON a.数据元标识符 = b.数据元标识符";
        }
        else if ((parseInt(lv) == 2 && cid == "*4") || (parseInt(lv) == 3 && pid == "*4")) {
            strsql = "SELECT '' AS 内部标识符, a.数据集编码, a.数据元标识符, a.数据元名称, 定义, 类型, 格式, 数据元允许值, b.值域编码                         FROM dbo.卫生信息数据元WS363 a                         LEFT JOIN dbo.卫生信息数据元值域目录WS364 b ON a.数据元标识符 = b.数据元标识符";
        }
        else if ((parseInt(lv) == 2 && cid == "*5") || (parseInt(lv) == 3 && pid == "*5")) {
            strsql = "SELECT '' AS 内部标识符, a.数据集编码, a.数据元标识符, a.数据元名称, 定义, 类型, 表示格式 AS 格式, 数据元允许值, b.值域编码                         FROM dbo.数据元 a                         LEFT JOIN dbo.数据元值域目录 b ON a.数据元标识符 = b.数据元标识符 AND b.数据元标识符 IS NOT NULL";
        }
        strsql = "select * from (" + strsql + ") t where 1=1 ";
        //第三层节点过滤“数据集编码”
        if (parseInt(lv) == 3) {
            strsql = strsql + " and 数据集编码='" + cid + "'";
        }
        if (keywords != "") {
            strsql = strsql + " and (内部标识符 like '%" + keywords + "%' or 数据元标识符 like '%" + keywords + "%' or 数据元名称 like '%" + keywords + "%' ) ";
        }
        if (onlyValue == "true") {
            strsql = strsql + " and 值域编码 is not null";
        }
        //获取分页Sql和条数
        var list = TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, null, pageInfo);
        return { list: list, count: pageInfo.totalRecord };
    };
    //获取值域数据
    tsgbdataController.prototype.getrangedata = function () {
        var cid = TSLobsterAPI.Program.RequestQuery("cid", "");
        var pid = TSLobsterAPI.Program.RequestQuery("pid", "");
        var lv = TSLobsterAPI.Program.RequestQuery("lv", "");
        var rangeId = TSLobsterAPI.Program.RequestQuery("rangeId", "");
        var pageInfo = {
            key: "值",
            page: TSLobsterAPI.Program.RequestQuery('page', 0),
            perPage: TSLobsterAPI.Program.RequestQuery('limit', 10),
            totalRecord: 0,
            totalPage: 0
        };
        var strsql = "";
        if ((parseInt(lv) == 2 && cid == "*1") || (parseInt(lv) == 3 && pid == "*1")) {
            strsql = "SELECT [值], [值含义], [说明], [值域编码], [值域名称]             FROM [城乡居民健康档案基本数据集值域WS365]";
        }
        else if ((parseInt(lv) == 2 && cid == "*2") || (parseInt(lv) == 3 && pid == "*2")) {
            strsql = "SELECT [值], [值含义], [说明], [值域编码], [值域名称]             FROM [电子病历数据集值域WS445]";
        }
        else if ((parseInt(lv) == 2 && cid == "*3") || (parseInt(lv) == 3 && pid == "*3")) {
            strsql = "SELECT [值], [值含义], [说明], [值域编码], [值域名称]             FROM [公共卫生数据集值域WS371-377]";
        }
        else if ((parseInt(lv) == 2 && cid == "*4") || (parseInt(lv) == 3 && pid == "*4")) {
            strsql = "SELECT [值], [值含义], [说明], [值域编码], [值域名称]             FROM [卫生信息数据元值域WS364]";
        }
        else if ((parseInt(lv) == 2 && cid == "*5") || (parseInt(lv) == 3 && pid == "*5")) {
            strsql = "SELECT [值], [值含义], [说明], [值域编码], [值域名称]             FROM [数据元值域]";
        }
        strsql = "select * from (" + strsql + ") t where 值域编码='" + rangeId + "'";
        //获取分页Sql和条数
        var list = TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, null, pageInfo);
        return { list: list, count: pageInfo.totalRecord };
    };
    return tsgbdataController;
}());

